package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.user.mapper.UserMapper;
import com.hmall.user.pojo.Adderss;
import com.hmall.user.pojo.User;
import com.hmall.user.service.UserService;
import com.hmall.user.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Adderss> getUserById() {
        Long userId = ThreadLocalUtil.getUserId();
        List<Adderss> list = userMapper.selectAddressList(userId);
        return list;

    }

    @Override
    public Adderss getAddressById(Long id) {
//        return userMapper.selectById(id);
        Adderss adderss = userMapper.findAddress(id);
        return adderss;
    }

    @Override
    public User findUser(Long id) {

        return userMapper.findUser(id);
    }

    @Override
    public void updateUser(Long id, Long bs) {
        UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
        userUpdateWrapper.eq("id",id).set("balance",bs);
        //修改
        this.update(userUpdateWrapper);
    }


}
